package com.model.manyToOne;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "TB_AUTHOR")
public class Author {

	@Id
	@GenericGenerator(name = "generator", strategy = "increment")
	@GeneratedValue(generator = "generator")
	@Column(name = "ID", unique = true, nullable = false)
	private int id;
	
	@Column(name = "NAME", length = 30)
	private String name;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "author")
	@Cascade(value = { CascadeType.SAVE_UPDATE, CascadeType.DELETE})
	private List<Book> books = new ArrayList<Book>();
	
	public Author() {
    }

    public Author(String name) {
        this.name = name;
    }

    public int getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Book> getBooks() {
		return books;
	}

	public void setBooks(List<Book> books) {
		this.books = books;
	}


}
